#include <QWindow>
#include <QFileInfo>

#include <windows.h>

#include "qlsembedwidget.h"
#include "ui_qlsembedwidget.h"
#include "../../QLsFunc/qlsfunc.h"

QLsEmbedWidget::QLsEmbedWidget(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::QLsEmbedWidget),
	m_type(EmbedType::Embed_Empty),
	m_wid(0),
	m_fileName("")
{
	ui->setupUi(this);
}

QLsEmbedWidget::~QLsEmbedWidget()
{
	QLsFunc::CloseWindowHandleByWID(m_wid);

	delete ui;
}

void QLsEmbedWidget::Embed()
{
	QLsFunc::CloseWindowHandleByWID(m_wid);

	switch (m_type)
	{
	case EmbedType::Embed_Empty:
		break;
	case EmbedType::Embed_Exe:
		break;
	case EmbedType::Embed_Word:
		if(!m_fileName.isEmpty() &&
				(m_fileName.endsWith(".doc") ||
				 m_fileName.endsWith(".docx")))
		{
			m_wid = QLsFunc::OpenWordInsetWidget(this, QFileInfo(m_fileName).absoluteFilePath());
		}
		break;
	case EmbedType::Embed_Ppt:
		if(!m_fileName.isEmpty() &&
				(m_fileName.endsWith(".ppt") ||
				 m_fileName.endsWith(".pptx")))
		{
			m_wid = QLsFunc::OpenPptInsetWidget(this, QFileInfo(m_fileName).absoluteFilePath());
		}
		break;
	default:
		break;
	}
}

QLsEmbedWidget::EmbedType QLsEmbedWidget::type() const
{
	return m_type;
}

void QLsEmbedWidget::setType(const EmbedType &type)
{
	m_type = type;
}

WId QLsEmbedWidget::wid() const
{
	return m_wid;
}

void QLsEmbedWidget::setWid(const WId &wid)
{
	m_wid = wid;
}

QString QLsEmbedWidget::fileName() const
{
	return m_fileName;
}

void QLsEmbedWidget::setFileName(const QString &fileName)
{
	m_fileName = fileName;
}
